<div class="row">
  <div class="col-lg-2">
    <div class="card">
      <div class="card-body">
        <h3 class="card-title">选择分类</h3>
        <div class="row">
          <div class="col-md-12">
            <%= shop_categories_tree %>
          </div>
        </div>
      </div>
    </div>
  </div>
  <div class="col-lg-10">
  <% if @shop_category.presence %>
    <%= form_for [:shop, @spu], html: { class: "card" } do |f| %>
      <div class="card-body">
        <h3 class="card-title">创建商品</h3>
        <div class="row">

          <div class="col-md-6">
            <div class="form-group">
              <label class="form-label">商品名字</label>
              <%= f.text_field :name, class: "form-control" %>
            </div>
          </div>

          <div class="col-md-6">
            <div class="form-group">
              <label class="form-label">封面</label>
              <div class="custom-file">
                <%= f.file_field :avatar, class: "custom-file-input" %>
                <label class="custom-file-label">选择文件</label>
              </div>
            </div>
          </div>
          <div class="col-md-4">
            <div class="form-group">
              <label class="form-label">分类</label>
              <% if @shop_category.presence %>
              <input type="text" name="shop_category" class="form-control" value="<%= @shop_category.name %>" disabled>
              <%= f.hidden_field :shop_category_id, value: @shop_category.id %>
              <% else %>
              <input type="text" name="no_shop_category" class="form-control" value="" disabled>
              <% end %>
            </div>
          </div>
          <div class="col-md-4">
            <div class="form-group">
              <label class="form-label">本店分类</label>
              <% if current_shoper.shop.spu_categories.where("parent_id = 0 OR parent_id IS NULL").count > 0 %>
              <select id="spu_spu_category_id" name="spu[spu_category_id]" class="form-control select">
                <% current_shoper.shop.spu_categories.where("parent_id = 0 OR parent_id IS NULL").each do |spu_category| %>
                <optgroup label="<%= spu_category.name %>">
                  <% spu_category.children.each do |child| %>
                  <option value="<%= child.id %>"><%= child.name %></option>
                  <% end %>
                </optgroup>
                <% end %>
              </select>
              <% else %>
              <input type="text" name="no_spu_category" class="form-control" value="没有设置分类" disabled>
              <% end %>
            </div>
          </div>
          <div class="col-md-4">
            <div class="form-group">
              <label class="form-label">最少库存</label>
              <%= f.number_field :min_stock, class: "form-control" %>
            </div>
          </div>
          <div class="col-md-4">
            <div class="form-group">
              <label class="form-label">最大库存</label>
              <%= f.number_field :max_stock, class: "form-control" %>
            </div>
          </div>
          <div class="col-md-4">
            <div class="form-group">
              <label class="form-label">运费模版</label>
              <%= f.select :fare_template_id, current_shoper.shop.fare_templates.map{ |c| [c.name, c.id] }, { include_blank: '请选择模版' }, { class: 'form-control select' } %>
            </div>
          </div>
          <div class="col-md-4">
            <div class="form-group">
              <label class="form-label">品牌（可不选）</label>
              <%= f.select :brand_id, @shop_category.parent.parent.brands.map{ |c| [c.name, c.id] }, { include_blank: '请选择品牌' }, { class: 'form-control select' } %>
            </div>
          </div>
          <div class="col-md-4">
            <div class="form-group">
              <label class="form-label">是否进行促销</label>
              <div class="custom-controls-stacked">
                <label class="custom-control custom-checkbox">
                  <%= f.check_box :promotion, class: "custom-control-input" %>
                  <span class="custom-control-label">勾选进行促销</span>
                </label>
              </div>
            </div>
          </div>
          <div class="col-md-4">
            <div class="form-group">
              <label class="form-label">能否使用优惠券</label>
              <div class="custom-controls-stacked">
                <label class="custom-control custom-checkbox">
                  <%= f.check_box :can_use_coupon, class: "custom-control-input" %>
                  <span class="custom-control-label">勾选可使用优惠券</span>
                </label>
              </div>
            </div>
          </div>
          <div class="col-md-12">
            <div class="form-group">
              <label class="form-label">承诺服务</label>
              <div class="selectgroup selectgroup-pills">
                <% ServiceItem.all.each do |service_item| %>
                  <label class="selectgroup-item">
                    <%= check_box_tag "spu[service_item_ids][]", service_item.id, f.object.service_items.include?(service_item), class: "selectgroup-input" %>
                    <span class="selectgroup-button">
                      <%= service_item.name %>
                    </span>
                  </label>
                <% end %>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="card-footer text-right">
        <%= f.submit "保 存", class: "btn btn-primary" %>
      </div>
    <% end %>
  <% end %>
  </div>
</div>